#
# Copyright (C) 2007-2015 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=dbus
PKG_VERSION:=1.13.18
PKG_RELEASE:=8

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://dbus.freedesktop.org/releases/dbus
PKG_HASH:=8078f5c25e34ab907ce06905d969dc8ef0ccbec367e1e1707c7ecf8460f4254e

PKG_MAINTAINER:=
PKG_LICENSE:=AFL-2.1
PKG_CPE_ID:=cpe:/a:freedesktop:dbus

PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1

PKG_CONFIG_DEPENDS:= \
	CONFIG_DBUS_VERBOSE

include $(INCLUDE_DIR)/package.mk

define Package/dbus/Default
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=Simple interprocess messaging system
  URL:=https://dbus.freedesktop.org/
endef

define Package/dbus/Default/description
 D-Bus is a message bus system, a simple way for applications to talk to one
 another. In addition to interprocess communication, D-Bus helps coordinate
 process lifecycle; it makes it simple and reliable to code a "single instance"
 application or daemon, and to launch applications and daemons on demand when
 their services are needed.
endef

define Package/libdbus
$(call Package/dbus/Default)
  CATEGORY:=Libraries
  TITLE+= (library)
  DEPENDS:= +libpthread
endef

define Package/libdbus/Description
$(call Package/dbus/Default/description)
 This package contains the D-Bus shared library.
endef

define Package/dbus
$(call Package/dbus/Default)
 TITLE+= (daemon)
 DEPENDS:= +libexpat +libdbus
endef

define Package/dbus/Description
$(call Package/dbus/Default/description)
 This package contains the D-Bus daemon.
endef

define Package/dbus-utils
$(call Package/dbus/Default)
 TITLE+= (utilities)
 DEPENDS:= +dbus
endef

define Package/dbus-utils/Description
$(call Package/dbus/Default/description)
 This package contains D-Bus utilities.
endef

define Package/dbus/config
  source "$(SOURCE)/Config.in"
endef

CONFIGURE_ARGS += \
	--disable-maintainer-mode \
	--disable-developer \
	--enable-debug=no \
	--enable-shared \
	--disable-static \
	--disable-verbose-mode \
	--disable-asserts \
	--disable-xml-docs \
	--disable-doxygen-docs \
	--disable-ducktype-docs \
	--disable-selinux \
	--disable-apparmor \
	--disable-libaudit \
	--enable-inotify \
	--disable-kqueue \
	--disable-console-owner-file \
	--disable-systemd \
	--disable-tests \
	--disable-code-coverage \
	--disable-x11-autolaunch \
	--with-session-socket-dir=/opt/tmp \
	--with-system-socket=/opt/var/run/dbus/system_bus_socket \
	--with-system-pid-file=/opt/var/run/dbus.pid \
	--with-dbus-user=root \
	--without-x \
	--enable-qt-help=no \
	--disable-xml-docs

ifeq ($(CONFIG_DBUS_VERBOSE),y)
  CONFIGURE_ARGS += --enable-verbose-mode
endif

define Build/InstallDev
	$(INSTALL_DIR) $(1)/opt/include
	$(CP) $(PKG_INSTALL_DIR)/opt/include/dbus-1.0 $(1)/opt/include/
	$(INSTALL_DIR) $(1)/opt/lib/dbus-1.0/include/dbus/
	$(INSTALL_DATA) \
		$(PKG_INSTALL_DIR)/opt/lib/dbus-1.0/include/dbus/*.h \
		$(1)/opt/lib/dbus-1.0/include/dbus/
	$(INSTALL_DIR) $(1)/opt/lib
	$(INSTALL_DATA) $(PKG_INSTALL_DIR)/opt/lib/libdbus-1.so* \
		$(1)/opt/lib/
	$(CP) $(PKG_INSTALL_DIR)/opt/lib/dbus-1.0 $(1)/opt/lib/
	$(INSTALL_DIR) $(1)/opt/lib/pkgconfig
	$(INSTALL_DATA) $(PKG_INSTALL_DIR)/opt/lib/pkgconfig/dbus-1.pc \
		$(1)/opt/lib/pkgconfig/
endef

define Package/libdbus/install
	$(INSTALL_DIR) $(1)/opt/lib
	$(CP) $(PKG_INSTALL_DIR)/opt/lib/libdbus-1.so.* $(1)/opt/lib/
endef

define Package/dbus/install
	$(INSTALL_DIR) $(1)/opt/bin
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/opt/bin/dbus-cleanup-sockets $(1)/opt/bin/
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/opt/bin/dbus-daemon $(1)/opt/bin/
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/opt/bin/dbus-launch $(1)/opt/bin/dbus-launch.real
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/opt/bin/dbus-uuidgen $(1)/opt/bin/
	$(INSTALL_BIN) ./files/dbus-launch $(1)/opt/bin/
	$(INSTALL_DIR) $(1)/opt/lib
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/opt/lib/dbus-daemon-launch-helper $(1)/opt/lib/
	$(INSTALL_DIR) $(1)/opt/etc/init.d
	$(INSTALL_BIN) ./files/S20dbus $(1)/opt/etc/init.d/
	$(INSTALL_DIR) $(1)/opt/share/dbus-1
	$(CP) $(PKG_INSTALL_DIR)/opt/share/dbus-1 $(1)/opt/share/
	$(INSTALL_DIR) $(1)/opt/var/run/dbus
endef

define Package/dbus-utils/install
	$(INSTALL_DIR) $(1)/opt/bin
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/opt/bin/dbus-monitor $(1)/opt/bin/
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/opt/bin/dbus-send $(1)/opt/bin/
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/opt/bin/dbus-test-tool $(1)/opt/bin/
endef

$(eval $(call BuildPackage,libdbus))
$(eval $(call BuildPackage,dbus))
$(eval $(call BuildPackage,dbus-utils))
